﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DispatchAssist.BusinessLogical.Model
{
    public class CacheEarlyTime
    {

        private List<EarlyWarning> _list;

        public List<EarlyWarning> InitList
        {
            get { return _list; }
        }

        public CacheEarlyTime(List<EarlyWarning> list)
        {
            _list = list;
        }

        public int GetEarlyTime(string airPort)
        {
            
            List<EarlyWarning> list = _list.Where(f => f.Airport == airPort).ToList();

            if (list.Count == 1)
            {
                return list[0].AOCEarlyTime;
            }
            else if (list.Count < 1)
            {
                List<EarlyWarning> defaultValue = _list.Where(f => f.Airport == "0000").ToList();
                return defaultValue[0].AOCEarlyTime;
            }
            else
            {
                throw new Exception("AirPort EarlyTime match error");
            }

        }

        public int GetSMSEarlyTime(string airPort)
        {

            List<EarlyWarning> list = _list.Where(f => f.Airport == airPort).ToList();

            if (list.Count == 1)
            {
                return list[0].SMSEarlyTime;
            }
            else if (list.Count < 1)
            {
                List<EarlyWarning> defaultValue = _list.Where(f => f.Airport == "0000").ToList();
                return defaultValue[0].SMSEarlyTime;
            }
            else
            {
                throw new Exception("AirPort EarlyTime match error");
            }

        }
    }
}
